using System;
using System.Diagnostics;
using System.Globalization;

namespace Atomic.Libraries.Physics.Units
{
	[Serializable]
	[DebuggerDisplay("{DebuggerDisplay}")]
	public class Volume : IQuantity
	{
		private double value;

		private Volume(double value)
		{
			this.value = value;
		}

		public static Volume FromUnit(IUnitSystem system, double value)
		{
			return new Volume(value / (system.LengthScaling * system.LengthScaling * system.LengthScaling));
		}

		public static Volume FromCubicAngstrom(double value)
		{
			return FromUnit(UnitSystem.AtomicSystem, value);
		}

		public static Volume FromCubicMeter(double value)
		{
			return FromUnit(UnitSystem.InternationalSystem, value);
		}
		
		public double ToUnit(IUnitSystem system)
		{
			return value * system.LengthScaling * system.LengthScaling * system.LengthScaling;
		}

		public double ToCubicAngstrom()
		{
			return ToUnit(UnitSystem.AtomicSystem);
		}

		public double ToCubicMeter()
		{
			return ToUnit(UnitSystem.InternationalSystem);
		}

		public static implicit operator double(Volume value)
		{
			return value.ToCubicAngstrom();
		}

		public static implicit operator Volume(double value)
		{
			return FromCubicAngstrom(value);
		}

		private string DebuggerDisplay
		{
			get
			{
				return string.Format(CultureInfo.InvariantCulture, "{0} Å^3 = {1} m^3", ToCubicAngstrom(), ToCubicMeter());
			}
		}
	}
}
